<%--
  Created by IntelliJ IDEA.
  User: CXYZF
  Date: 2024/10/17
  Time: 23:12
  To change this template use File | Settings | File Templates.
--%>
<<%--
  Created by IntelliJ IDEA.
  User: 王梦雨
  Date: 2024/9/27
  Time: 14:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="java.sql.*" %>
<% request.setCharacterEncoding("UTF-8");%>
<% String id = request.getParameter("stuid");%>
<html>
<head>
  <title>修改结果</title>
  <%! ResultSet rs;%>
  <%
    String dbName = "school";//数据库
    String userName ="root";//账户
    String userPassword ="wmy123";//密码
    String url ="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPassword;
    Class.forName("com.mysql.cj.jdbc.Driver");//5.7以下不加.cj
    Connection conn = DriverManager.getConnection(url);//连接数据库
    String sql = "DELETE from student where number =?";//查询学生表所有字段
    PreparedStatement preparedStatement = conn.prepareStatement(sql);//创建操作对象
    preparedStatement.setString(1,id);
    int rsult = preparedStatement.executeUpdate();//运行sql命令查询数据 结果放到rs结果集中
    if (rsult>0){
      out.print("<script type='text/javascript>alert('删除成功')</script>");
    }else {
      out.print("<script type='text/javascript>alert('删除成功')</script>");
    }
    sql = "select  * from student";
    rs = preparedStatement.executeQuery(sql);
  %>
</head>
<body>
<table border="1">
  <th colpan="4" style="font-size: x-large;alignment:center">学生表信息</th>
  <tr style="text-align: center">
    <td>学号</td>
    <td>姓名</td>
    <td>出生日期</td>
    <td>所在班级</td>
  </tr>
  <% while (rs.next()){%>
  <tr style="text-align: center">
    <td><%=rs.getString(1) %></td>
    <td><%=rs.getString(2) %></td>
    <td><%=rs.getString("birthday") %></td>
    <td><%=rs.getString("stuclass") %></td>
  </tr>
  <% } %>
  <%
    rs.close();
    preparedStatement.close();
    conn.close();
  %>
</table>
</body>
</html>